#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int subarraySum(vector<int>& nums, int k) {
        unordered_map<int, int> m;
        m[0] = 1;

        int sum = 0, countK = 0;
        for (auto x : nums)
        {
            sum += x;
            if (m.count(sum - k))
                countK += m[sum - k];
            m[sum]++;
        }
        return countK;

    }
};